<template>
  <div class="app-container btn">
    <el-form
      :model="queryParams"
      ref="queryForm"
      :inline="true"
      v-show="showSearch"
      label-width="100px"
      size="medium"
    >
      <el-form-item class="item" label="表名" prop="tableName" size="medium">
        <el-input
          v-model="queryParams.tableName"
          placeholder="请输入表名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="模板ID" prop="schemaId">
        <el-input
          v-model="queryParams.schemaId"
          placeholder="请输入模板ID"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="行数" prop="total">
        <el-input
          v-model="queryParams.total"
          placeholder="请输入行数"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="清洗状态" prop="dataState">
        <el-input
          v-model="queryParams.dataState"
          placeholder="请输入表清洗状态"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="血缘ID" prop="dataSource">
        <el-input
          v-model="queryParams.dataSource"
          placeholder="请输入血缘ID"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="保存位置" prop="storeLoc">
        <el-input
          v-model="queryParams.storeLoc"
          placeholder="请输入数据保存位置"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="产生账号" prop="createrId">
        <el-input
          v-model="queryParams.createrId"
          placeholder="请输入产生账号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="small"
          @click="handleQuery"
          style="margin-left: 50px"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="small" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="small"
          @click="handleAdd"
          v-hasPermi="['scckocMeta:scckocMeta:add']"
          >新增</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="small"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['scckocMeta:scckocMeta:edit']"
          >修改</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="small"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['scckocMeta:scckocMeta:remove']"
          >删除</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="small"
          :loading="exportLoading"
          @click="handleExport"
          v-hasPermi="['scckocMeta:scckocMeta:export']"
          >导出</el-button
        >
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table
      v-loading="loading"
      :data="scckocMetaList"
      @selection-change="handleSelectionChange"
      border
      :header-cell-style="{ 'font-size': '17px' }"
      :cell-style="changeCellStyle"
      style="width: 100%; font-size: 17px"
    >
      <el-table-column type="selection" width="50" fixed align="center" />
      <el-table-column label="ID" width="60" fixed align="center" prop="id" />
      <el-table-column
        label="表名"
        width="150"
        align="center"
        prop="tableName"
      />
      <el-table-column
        label="模板ID"
        width="100"
        align="center"
        prop="schemaId"
      />
      <el-table-column label="行数" width="80" align="center" prop="total" />
      <el-table-column
        label="表清洗状态"
        width="150"
        align="center"
        prop="dataState"
      />
      <el-table-column
        label="血缘ID"
        width="150"
        align="center"
        prop="dataSource"
      />
      <el-table-column
        label="表状态"
        width="80"
        align="center"
        prop="dataType"
      />
      <el-table-column
        label="数据保存位置"
        align="center"
        width="700"
        prop="storeLoc"
      />
      <el-table-column
        label="产生账号"
        width="100"
        align="center"
        prop="createrId"
      />
      <el-table-column
        label="操作"
        width="124"
        align="center"
        fixed="right"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['scckocMeta:scckocMeta:edit']"
            >修改</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['scckocMeta:scckocMeta:remove']"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      class="pagination_style"
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改库的元数据对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <el-form-item label="表名" prop="tableName">
          <el-input v-model="form.tableName" placeholder="请输入表名" />
        </el-form-item>
        <el-form-item label="模板ID" prop="schemaId">
          <el-input v-model="form.schemaId" placeholder="请输入模板ID" />
        </el-form-item>
        <el-form-item label="行数" prop="total">
          <el-input v-model="form.total" placeholder="请输入行数" />
        </el-form-item>
        <el-form-item label="表清洗状态" prop="dataState">
          <el-input v-model="form.dataState" placeholder="请输入表清洗状态" />
        </el-form-item>
        <el-form-item label="血缘ID" prop="dataSource">
          <el-input v-model="form.dataSource" placeholder="请输入血缘ID" />
        </el-form-item>
        <el-form-item label="表状态" prop="dataType">
          <el-input
            v-model="form.dataType"
            type="textarea"
            placeholder="请输入内容"
          />
        </el-form-item>
        <el-form-item label="数据保存位置" prop="storeLoc">
          <el-input v-model="form.storeLoc" placeholder="请输入数据保存位置" />
        </el-form-item>
        <el-form-item label="产生账号" prop="createrId">
          <el-input v-model="form.createrId" placeholder="请输入产生账号" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listScckocMeta,
  getScckocMeta,
  delScckocMeta,
  addScckocMeta,
  updateScckocMeta,
  exportScckocMeta,
} from "@/api/scckocMeta/scckocMeta";

export default {
  name: "ScckocMeta",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 库的元数据表格数据
      scckocMetaList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        tableName: null,
        schemaId: null,
        total: null,
        dataState: null,
        dataSource: null,
        dataType: null,
        storeLoc: null,
        createrId: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询库的元数据列表 */
    getList() {
      this.loading = true;
      this.page = this.queryParams.pageNum;
      this.size = this.pageSize;
      listScckocMeta(this.queryParams).then((response) => {
        this.scckocMetaList = response.data.rows;
        this.total = response.data.total;
        this.loading = false;

        console.log(this.scckocMetaList, "this.scckocMetaList");
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        tableName: null,
        schemaId: null,
        total: null,
        dataState: null,
        dataSource: null,
        dataType: null,
        storeLoc: null,
        createTime: null,
        createrId: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    //修改table(数据保存列样式)
    changeCellStyle(row, column, rowIndex, columnIndex) {
      if (row.column.label === "数据保存位置") {
        return "font-size: 16px"; // 修改的样式
      } else {
        return "";
      }
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加库的元数据";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids;
      getScckocMeta(id).then((response) => {
        this.form = response.data;
        this.open = true;
        this.title = "修改库的元数据";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.id != null) {
            updateScckocMeta(this.form).then((response) => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addScckocMeta(this.form).then((response) => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm(
        '是否确认删除库的元数据编号为"' + ids + '"的数据项?',
        "警告",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }
      )
        .then(function () {
          return delScckocMeta(ids);
        })
        .then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm("是否确认导出所有库的元数据数据项?", "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.exportLoading = true;
          return exportScckocMeta(queryParams);
        })
        .then((response) => {
          this.download(response.msg);
          this.exportLoading = false;
        })
        .catch(() => {});
    },
  },
};
</script>

<style lang="scss" scoped>
::v-deep .el-form-item__label {
  font-size: 17px;
}
::v-deep .mb8 .el-button {
  font-size: 16px;
}
::v-deep .el-form .el-button {
  font-size: 16px;
}
</style>

<style lang="scss" scoped>
::v-deep .el-form-item__label {
  font-size: 17px;
}
::v-deep .mb8 .el-button {
  font-size: 16px;
}
::v-deep .el-form .el-button {
  font-size: 16px;
}
// ::v-deep .el-form  .el-form-item {
// width: 24%;
// }

::v-deep .el-form .el-form-item {
  .el-form-item__error {
    width: 120px;
  }
}

::v-deep .el-dialog .el-form-item__label {
  width: 30px;
}

//去除input number样式
::v-deep input::-webkit-outer-spin-button,
::v-deep input::-webkit-inner-spin-button {
  -webkit-appearance: none !important;
}
::v-deep input[type="number"] {
  -moz-appearance: textfield !important;
}
::v-deep .el-dialog .el-input__inner {
  width: 300px;
  line-height: 1px !important;
}

.element.style {
  width: 100px;
  min-width: 100px;
}

.app-container {
  background: rgb(254, 254, 254);
}

.pagination_style {
  height: 70px;
  margin-right: 40px;
}

.btn {
  .el-button {
    margin-left: 10px;
    margin-right: 5px;
  }
}
</style>
